package {
	import flash.geom.Point;
	
	import com.passioneffect.adapter.ContentMovieClipAdapter;
	import com.passioneffect.display.Component;
	import com.passioneffect.layout.FlowEffectLayout;	

	/**
	 * @author Passion Effect
	 */
	public class CarouselFlowLayout extends FlowEffectLayout {
		public function CarouselFlowLayout(component : Component) {
			super(component);
		}
		
		override public function draw(index : int) : Point {
			var tx : Number = 0;
			var ty : Number = 0;
			
			var offset : Number;
			
			if(getTotalLengthX()>component.compLengthX){
				tx = index * (unselectedX + spacing) - scrollValueX;
			}else{
				tx=index*(unselectedX+spacing)+component.compLengthX;
			}
			
			ty = component.compLengthY / 2 - unselectedY / 2;
			
			if(getLayoutValue(index)) {
				ty -= (getLayoutValue(index).yLength - unselectedY) / 2;
			}
			
			var i : int;
			
			for(var adapter:Object in layoutValue) {
				i = ContentMovieClipAdapter(adapter).getIndex();
				if(index > i) {
					offset = layoutValue[adapter].xLength - unselectedX;
					if(component.direction=="horizontal"){
						tx += offset;
					}else{
						tx+=offset;
					}
					
				}
			}
			
			if(direction == "horizontal") {
				return new Point(tx, ty);
			}else {
				return new Point(ty, tx);
			}
		}
		
	}
}
